//
//  HMUserAccount.swift
//  webo
//
//  Created by apple on 2016/11/15.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class HMUserAccount: NSObject,NSCoding {
   
    var access_token: String?
    
    var expires_in: Double = 0 {
        didSet{
            //创建一个从现在开始计算日期
        expires_date = Date(timeIntervalSinceNow: expires_in)
        }
    }
    var expires_date: Date?
    var uid: String?
    
    var name: String?
    var avatar_large: String?
    
    //字典解模型
    init(dict: [String : Any]) {
        super.init()
        setValuesForKeys(dict)
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
    }
//接档
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as! String?
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as! Date?
        uid = aDecoder.decodeObject(forKey: "uid") as! String?
        name = aDecoder.decodeObject(forKey: "name") as! String?
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as! String?

    }
//    归档，转化为二进制数
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(name, forKey: "name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
    
}

